{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "from selenium import webdriver"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [],
   "source": [
    "navegator = webdriver.Firefox()\n",
    "#navegator = webdriver.ChromeService(executable_path=r'C:\\Users\\Arthur\\anaconda3\\chromedriver')\n",
    "navegator.get('https://www3.bcb.gov.br/ifdata/#!')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [],
   "source": [
    "import time\n",
    "from selenium.webdriver.common.by import By\n",
    "time.sleep(5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [],
   "source": [
    "from selenium.webdriver.support.ui import Select"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [],
   "source": [
    "time.sleep(5)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 115,
   "metadata": {},
   "outputs": [],
   "source": [
    "#/html/body/form/div[2]/div[2]/div/div[1]/ul/li[73]/a\n",
    "#/html/body/form/div[2]/div[2]/div/div[1]/ul/li[2]/a\n",
    "\n",
    "#/html/body/form/div[2]/div[2]/div/div[1]/ul/li[24]/a\n",
    "#/html/body/form/div[2]/div[2]/div/div[1]/ul/li[23]/a\n",
    "#/html/body/form/div[2]/div[2]/div/div[1]/ul/li[24]/a\n",
    "\n",
    "\n",
    "#/html/body/form/div[2]/div[2]/div/div[1]/button[2]\n",
    "#//*[@id=\"btnDataBase\"]\n",
    "\n",
    "   \n",
    "    #Tipo de instituição:\n",
    "\n",
    "#/html/body/form/div[2]/div[2]/div/div[2]/button[2]\n",
    "#//*[@id=\"btnTipoInst\"]\n",
    "#//*[@id=\"btnTipoInst\"]\n",
    "#/html/body/form/div[2]/div[2]/div/div[2]/button[2]\n",
    "\n",
    "#/html/body/form/div[2]/div[2]/div/div[2]/ul/li[3]/a\n",
    "\n",
    "    #Tipo de relatório: Resumo\n",
    "\n",
    "#/html/body/form/div[2]/div[2]/div/div[3]/button[2]\n",
    "#//*[@id=\"btnRelatorio\"]\n",
    "\n",
    "#/html/body/form/div[2]/div[2]/div/div[3]/ul/li[1]/a\n",
    "\n",
    "\n",
    "#navegator.execute_script(\"window.scrollTo(0, Y)\")\n",
    "\n",
    "#iframe = navegator.find_element(By.XPATH, \"html/body/form/div[2]/div[2]/div/div[1]/ul/li[30]/a\")\n",
    "   # ActionChains(navegator)\\\n",
    "      #  .scroll_to_element(iframe)\\\n",
    "     #   .perform()  \n",
    "#navegator.scroll_to_ele        \n",
    "#navegator.spec_from_file_location(name, location, *, loader=None, submodule_search_locations=None)\n",
    "\n",
    "#navegator.find_element(By.XPATH, '//*[@id=\"btnDataBase\"]').click()\n",
    "#time.sleep(1)\n",
    "#navegator.execute_script(\"window.scrollTo(0, document.body.scrollHeight);\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 141,
   "metadata": {},
   "outputs": [],
   "source": [
    "#key = 1\n",
    "#count = 0\n",
    "#while key < 23:\n",
    " #   key_add = \"html/body/form/div[2]/div[2]/div/div[1]/ul/li[\"+str(key)+\"]/a\"\n",
    " #   print(key_add)\n",
    "  #  key += 1\n",
    "  #  count += 1\n",
    "  #  print(count)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[1]/a\n",
      "1\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[2]/a\n",
      "2\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[3]/a\n",
      "3\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[4]/a\n",
      "4\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[5]/a\n",
      "5\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[6]/a\n",
      "6\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[7]/a\n",
      "7\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[8]/a\n",
      "8\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[9]/a\n",
      "9\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[10]/a\n",
      "10\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[11]/a\n",
      "11\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[12]/a\n",
      "12\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[13]/a\n",
      "13\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[14]/a\n",
      "14\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[15]/a\n",
      "15\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[16]/a\n",
      "16\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[17]/a\n",
      "17\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[18]/a\n",
      "18\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[19]/a\n",
      "19\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[20]/a\n",
      "20\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[21]/a\n",
      "21\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[22]/a\n",
      "22\n"
     ]
    }
   ],
   "source": [
    "# de dez/2022 a set/2017, pois aqui não precisa dar scroll para baixo\n",
    "key = 1\n",
    "count = 0\n",
    "while key < 23:\n",
    "    key_add = \"html/body/form/div[2]/div[2]/div/div[1]/ul/li[\"+str(key)+\"]/a\"\n",
    "    print(key_add)\n",
    "    key += 1\n",
    "    count += 1\n",
    "    print(count)\n",
    "    \n",
    "    \n",
    "    #Data-base:\n",
    "    navegator.find_element(By.XPATH, '//*[@id=\"btnDataBase\"]').click()\n",
    "    time.sleep(2)\n",
    "    navegator.find_element(By.XPATH, '/html/body/form/div[2]/div[2]/div/div[1]/ul/li['+str(key)+']/a').click()\n",
    "    time.sleep(2)\n",
    "    #Tipo de instituição:\n",
    "    navegator.find_element(By.XPATH, '//*[@id=\"btnTipoInst\"]').click()\n",
    "    time.sleep(2)\n",
    "    navegator.find_element(By.XPATH, '/html/body/form/div[2]/div[2]/div/div[2]/ul/li[3]/a').click()\n",
    "    #Tipo de relatório: Resumo\n",
    "    navegator.find_element(By.XPATH, '//*[@id=\"btnRelatorio\"]').click()\n",
    "    time.sleep(2)\n",
    "    navegator.find_element(By.XPATH, '/html/body/form/div[2]/div[2]/div/div[3]/ul/li[1]/a').click()\n",
    "    time.sleep(20)\n",
    "    #Donwload\n",
    "    navegator.find_element(By.XPATH, '//*[@id=\"aExportCsv\"]').click()\n",
    "    time.sleep(6)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[23]/a\n",
      "1\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[24]/a\n",
      "2\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[25]/a\n",
      "3\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[26]/a\n",
      "4\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[27]/a\n",
      "5\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[28]/a\n",
      "6\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[29]/a\n",
      "7\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[30]/a\n",
      "8\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[31]/a\n",
      "9\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[32]/a\n",
      "10\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[33]/a\n",
      "11\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[34]/a\n",
      "12\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[35]/a\n",
      "13\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[36]/a\n",
      "14\n"
     ]
    }
   ],
   "source": [
    "#key = 23\n",
    "#count = 0\n",
    "#while key < 37:\n",
    "  #  key_add = \"html/body/form/div[2]/div[2]/div/div[1]/ul/li[\"+str(key)+\"]/a\"\n",
    "  #  print(key_add)\n",
    "  #  key += 1\n",
    "  #  count += 1\n",
    "  #  print(count)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[23]/a\n",
      "1\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[24]/a\n",
      "2\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[25]/a\n",
      "3\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[26]/a\n",
      "4\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[27]/a\n",
      "5\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[28]/a\n",
      "6\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[29]/a\n",
      "7\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[30]/a\n",
      "8\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[31]/a\n",
      "9\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[32]/a\n",
      "10\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[33]/a\n",
      "11\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[34]/a\n",
      "12\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[35]/a\n",
      "13\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[36]/a\n",
      "14\n"
     ]
    }
   ],
   "source": [
    "# de jun/2017 até mar/2014, aqui precisa dar scroll para baixo\n",
    "key = 23\n",
    "count = 0\n",
    "while key < 37:\n",
    "    key_add = \"html/body/form/div[2]/div[2]/div/div[1]/ul/li[\"+str(key)+\"]/a\"\n",
    "    print(key_add)\n",
    "    key += 1\n",
    "    count += 1\n",
    "    print(count)\n",
    "    \n",
    "    \n",
    "    #Data-base:\n",
    "    navegator.find_element(By.XPATH, '//*[@id=\"btnDataBase\"]').click()\n",
    "    time.sleep(2)\n",
    "    # Execute um scroll down\n",
    "    navegator.execute_script(\"window.scrollTo(0, document.body.scrollHeight);\")  \n",
    "    time.sleep(3)\n",
    "    navegator.find_element(By.XPATH, '/html/body/form/div[2]/div[2]/div/div[1]/ul/li['+str(key)+']/a').click()\n",
    "    time.sleep(3)\n",
    "    # Execute um scroll up\n",
    "    navegator.execute_script(\"window.scrollTo(0, -document.body.scrollHeight);\")\n",
    "    #Tipo de instituição:\n",
    "    navegator.find_element(By.XPATH, '//*[@id=\"btnTipoInst\"]').click()\n",
    "    time.sleep(2)\n",
    "    navegator.find_element(By.XPATH, '/html/body/form/div[2]/div[2]/div/div[2]/ul/li[3]/a').click()\n",
    "    time.sleep(2)\n",
    "    #Tipo de relatório: Resumo\n",
    "    navegator.find_element(By.XPATH, '//*[@id=\"btnRelatorio\"]').click()\n",
    "    time.sleep(2)\n",
    "    navegator.find_element(By.XPATH, '/html/body/form/div[2]/div[2]/div/div[3]/ul/li[1]/a').click()\n",
    "    time.sleep(22)\n",
    "    #Donwload\n",
    "    navegator.find_element(By.XPATH, '//*[@id=\"aExportCsv\"]').click()\n",
    "    time.sleep(6)\n",
    "\n",
    "    \n",
    "    \n",
    "    \n",
    "    \n",
    "    # Não adianta pq o csv sempre vem com tudo\n",
    "    #Selecionar apenas cooperativas\n",
    "    #navegator.find_element(By.XPATH, '/html/body/form/div[7]/table[1]/thead/tr/th[5]/div/a[2]/i').click()\n",
    "   # time.sleep(1)\n",
    "   # navegator.find_element(By.XPATH, '//*[@id=\"cbFiltroAll\"]').click()\n",
    "   # time.sleep(1)\n",
    "  #  navegator.find_element(By.XPATH, '//*[@id=\"cbFiltro8\"]').click()\n",
    "  #  time.sleep(1)\n",
    "   # navegator.find_element(By.XPATH, '//*[@id=\"btnOk\"]').click()\n",
    "  #  time.sleep(4)\n",
    "   # navegator.find_element(By.XPATH, '//*[@id=\"aExportCsv\"]').click()\n",
    "  #  time.sleep(4)\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "#09/2022###/html/body/form/div[2]/div[2]/div/div[1]/ul/li[3]/a\n",
    "\n",
    "#03/2010#final#/html/body/form/div[2]/div[2]/div/div[1]/ul/li[53]/a\n",
    "    \n",
    "    \n",
    "    \n",
    "    \n",
    "    \n",
    "#if range(print(key_add)) == 50:\n",
    "    #print(\"Job Done!\")    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[37]/a\n",
      "1\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[38]/a\n",
      "2\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[39]/a\n",
      "3\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[40]/a\n",
      "4\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[41]/a\n",
      "5\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[42]/a\n",
      "6\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[43]/a\n",
      "7\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[44]/a\n",
      "8\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[45]/a\n",
      "9\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[46]/a\n",
      "10\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[47]/a\n",
      "11\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[48]/a\n",
      "12\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[49]/a\n",
      "13\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[50]/a\n",
      "14\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[51]/a\n",
      "15\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[52]/a\n",
      "16\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[53]/a\n",
      "17\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[54]/a\n",
      "18\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[55]/a\n",
      "19\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[56]/a\n",
      "20\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[57]/a\n",
      "21\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[58]/a\n",
      "22\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[59]/a\n",
      "23\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[60]/a\n",
      "24\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[61]/a\n",
      "25\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[62]/a\n",
      "26\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[63]/a\n",
      "27\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[64]/a\n",
      "28\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[65]/a\n",
      "29\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[66]/a\n",
      "30\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[67]/a\n",
      "31\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[68]/a\n",
      "32\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[69]/a\n",
      "33\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[70]/a\n",
      "34\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[71]/a\n",
      "35\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[72]/a\n",
      "36\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[73]/a\n",
      "37\n"
     ]
    }
   ],
   "source": [
    "#key = 37\n",
    "#count = 0\n",
    "#while key < 74:\n",
    "   # key_add = \"html/body/form/div[2]/div[2]/div/div[1]/ul/li[\"+str(key)+\"]/a\"\n",
    "   # print(key_add)\n",
    "   # key += 1\n",
    "   # count += 1\n",
    "   # print(count)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[37]/a\n",
      "1\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[38]/a\n",
      "2\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[39]/a\n",
      "3\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[40]/a\n",
      "4\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[41]/a\n",
      "5\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[42]/a\n",
      "6\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[43]/a\n",
      "7\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[44]/a\n",
      "8\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[45]/a\n",
      "9\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[46]/a\n",
      "10\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[47]/a\n",
      "11\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[48]/a\n",
      "12\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[49]/a\n",
      "13\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[50]/a\n",
      "14\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[51]/a\n",
      "15\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[52]/a\n",
      "16\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[53]/a\n",
      "17\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[54]/a\n",
      "18\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[55]/a\n",
      "19\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[56]/a\n",
      "20\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[57]/a\n",
      "21\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[58]/a\n",
      "22\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[59]/a\n",
      "23\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[60]/a\n",
      "24\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[61]/a\n",
      "25\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[62]/a\n",
      "26\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[63]/a\n",
      "27\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[64]/a\n",
      "28\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[65]/a\n",
      "29\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[66]/a\n",
      "30\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[67]/a\n",
      "31\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[68]/a\n",
      "32\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[69]/a\n",
      "33\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[70]/a\n",
      "34\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[71]/a\n",
      "35\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[72]/a\n",
      "36\n",
      "html/body/form/div[2]/div[2]/div/div[1]/ul/li[73]/a\n",
      "37\n"
     ]
    }
   ],
   "source": [
    "# de dez/2013 a mar/2005, aqui precisa dar scroll para baixo e mudou instituições individuais está na segunda posição\n",
    "key = 37\n",
    "count = 0\n",
    "while key < 73:\n",
    "    key_add = \"html/body/form/div[2]/div[2]/div/div[1]/ul/li[\"+str(key)+\"]/a\"\n",
    "    print(key_add)\n",
    "    key += 1\n",
    "    count += 1\n",
    "    print(count)\n",
    "    \n",
    "    \n",
    "    #Data-base:\n",
    "    navegator.find_element(By.XPATH, '//*[@id=\"btnDataBase\"]').click()\n",
    "    time.sleep(2)\n",
    "    # Execute um scroll down\n",
    "    navegator.execute_script(\"window.scrollTo(0, document.body.scrollHeight);\")  \n",
    "    time.sleep(3)\n",
    "    navegator.find_element(By.XPATH, '/html/body/form/div[2]/div[2]/div/div[1]/ul/li['+str(key)+']/a').click()\n",
    "    time.sleep(3)\n",
    "    # Execute um scroll up\n",
    "    navegator.execute_script(\"window.scrollTo(0, -document.body.scrollHeight);\")\n",
    "    #Tipo de instituição:\n",
    "    navegator.find_element(By.XPATH, '//*[@id=\"btnTipoInst\"]').click()\n",
    "    time.sleep(2)\n",
    "    #Aqui mudou pois agora instituições individuais está na segunda posição e não na terceira\n",
    "    navegator.find_element(By.XPATH, '/html/body/form/div[2]/div[2]/div/div[2]/ul/li[2]/a').click()\n",
    "    time.sleep(2)\n",
    "    #Tipo de relatório: Resumo\n",
    "    navegator.find_element(By.XPATH, '//*[@id=\"btnRelatorio\"]').click()\n",
    "    time.sleep(2)\n",
    "    navegator.find_element(By.XPATH, '/html/body/form/div[2]/div[2]/div/div[3]/ul/li[1]/a').click()\n",
    "    time.sleep(22)\n",
    "    #Donwload\n",
    "    navegator.find_element(By.XPATH, '//*[@id=\"aExportCsv\"]').click()\n",
    "    time.sleep(6)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['dados', 'dados(1)', 'dados(2)', 'dados(3)', 'dados(4)', 'dados(5)', 'dados(6)', 'dados(7)', 'dados(8)', 'dados(9)', 'dados(10)', 'dados(11)', 'dados(12)', 'dados(13)', 'dados(14)', 'dados(15)', 'dados(16)', 'dados(17)', 'dados(18)', 'dados(19)', 'dados(20)', 'dados(21)', 'dados(22)', 'dados(23)', 'dados(24)', 'dados(25)', 'dados(26)', 'dados(27)', 'dados(28)', 'dados(29)', 'dados(30)', 'dados(31)', 'dados(32)', 'dados(33)', 'dados(34)', 'dados(35)', 'dados(36)', 'dados(37)', 'dados(38)', 'dados(39)', 'dados(40)', 'dados(41)', 'dados(42)', 'dados(43)', 'dados(44)', 'dados(45)', 'dados(46)', 'dados(47)', 'dados(48)', 'dados(49)', 'dados(50)', 'dados(51)', 'dados(52)', 'dados(53)', 'dados(54)', 'dados(55)', 'dados(56)', 'dados(57)', 'dados(58)', 'dados(59)', 'dados(60)', 'dados(61)', 'dados(62)', 'dados(63)', 'dados(64)', 'dados(65)', 'dados(66)', 'dados(67)', 'dados(68)', 'dados(69)', 'dados(70)', 'dados(71)']\n"
     ]
    }
   ],
   "source": [
    "# Crie uma lista com os nomes dos arquivos gerados\n",
    "#nomes_gerados = []\n",
    "#for number in range(72):\n",
    "#    if number == 0:\n",
    "  #      nomes_gerados.append(\"dados\")\n",
    " #   else:\n",
    "  #      nomes_gerados.append(f\"dados({number})\")\n",
    "        \n",
    "#print(nomes_gerados)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "72"
      ]
     },
     "execution_count": 70,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Crie uma lista de datas trimestrais no formato \"mm-yyyy\"\n",
    "#datas_trimestrais = [\"12-2022\", \"09-2022\", \"06-2022\", \"03-2022\", \"12-2021\", \"09-2021\", \"06-2021\", \"03-2021\", \"12-2020\", \"09-2020\", \"06-2020\", \"03-2020\", \"12-2019\", \"09-2019\", \"06-2019\", \"03-2019\", \"12-2018\", \"09-2018\", \"06-2018\", \"03-2018\", \"12-2017\", \"09-2017\", \"06-2017\", \"03-2017\", \"12-2016\", \"09-2016\", \"06-2016\", \"03-2016\", \"12-2015\", \"09-2015\", \"06-2015\", \"03-2015\", \"12-2014\", \"09-2014\", \"06-2014\", \"03-2014\", \"12-2013\", \"09-2013\", \"06-2013\", \"03-2013\", \"12-2012\", \"09-2012\", \"06-2012\", \"03-2012\", \"12-2011\", \"09-2011\", \"06-2011\", \"03-2011\", \"12-2010\", \"09-2010\", \"06-2010\", \"03-2010\", \"12-2009\", \"09-2009\", \"06-2009\", \"03-2009\", \"12-2008\", \"09-2008\", \"06-2008\", \"03-2008\", \"12-2007\", \"09-2007\", \"06-2007\", \"03-2007\", \"12-2006\", \"09-2006\", \"06-2006\", \"03-2006\", \"12-2005\", \"09-2005\", \"06-2005\", \"03-2005\"]\n",
    "#len(datas_trimestrais)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Arquivo renomeado e movido: dados.csv -> 12-2022.csv\n",
      "Arquivo renomeado e movido: dados(1).csv -> 09-2022.csv\n",
      "Arquivo renomeado e movido: dados(2).csv -> 06-2022.csv\n",
      "Arquivo renomeado e movido: dados(3).csv -> 03-2022.csv\n",
      "Arquivo renomeado e movido: dados(4).csv -> 12-2021.csv\n",
      "Arquivo renomeado e movido: dados(5).csv -> 09-2021.csv\n",
      "Arquivo renomeado e movido: dados(6).csv -> 06-2021.csv\n",
      "Arquivo renomeado e movido: dados(7).csv -> 03-2021.csv\n",
      "Arquivo renomeado e movido: dados(8).csv -> 12-2020.csv\n",
      "Arquivo renomeado e movido: dados(9).csv -> 09-2020.csv\n",
      "Arquivo renomeado e movido: dados(10).csv -> 06-2020.csv\n",
      "Arquivo renomeado e movido: dados(11).csv -> 03-2020.csv\n",
      "Arquivo renomeado e movido: dados(12).csv -> 12-2019.csv\n",
      "Arquivo renomeado e movido: dados(13).csv -> 09-2019.csv\n",
      "Arquivo renomeado e movido: dados(14).csv -> 06-2019.csv\n",
      "Arquivo renomeado e movido: dados(15).csv -> 03-2019.csv\n",
      "Arquivo renomeado e movido: dados(16).csv -> 12-2018.csv\n",
      "Arquivo renomeado e movido: dados(17).csv -> 09-2018.csv\n",
      "Arquivo renomeado e movido: dados(18).csv -> 06-2018.csv\n",
      "Arquivo renomeado e movido: dados(19).csv -> 03-2018.csv\n",
      "Arquivo renomeado e movido: dados(20).csv -> 12-2017.csv\n",
      "Arquivo renomeado e movido: dados(21).csv -> 09-2017.csv\n",
      "Arquivo renomeado e movido: dados(22).csv -> 06-2017.csv\n",
      "Arquivo renomeado e movido: dados(23).csv -> 03-2017.csv\n",
      "Arquivo renomeado e movido: dados(24).csv -> 12-2016.csv\n",
      "Arquivo renomeado e movido: dados(25).csv -> 09-2016.csv\n",
      "Arquivo renomeado e movido: dados(26).csv -> 06-2016.csv\n",
      "Arquivo renomeado e movido: dados(27).csv -> 03-2016.csv\n",
      "Arquivo renomeado e movido: dados(28).csv -> 12-2015.csv\n",
      "Arquivo renomeado e movido: dados(29).csv -> 09-2015.csv\n",
      "Arquivo renomeado e movido: dados(30).csv -> 06-2015.csv\n",
      "Arquivo renomeado e movido: dados(31).csv -> 03-2015.csv\n",
      "Arquivo renomeado e movido: dados(32).csv -> 12-2014.csv\n",
      "Arquivo renomeado e movido: dados(33).csv -> 09-2014.csv\n",
      "Arquivo renomeado e movido: dados(34).csv -> 06-2014.csv\n",
      "Arquivo renomeado e movido: dados(35).csv -> 03-2014.csv\n",
      "Arquivo renomeado e movido: dados(36).csv -> 12-2013.csv\n",
      "Arquivo renomeado e movido: dados(37).csv -> 09-2013.csv\n",
      "Arquivo renomeado e movido: dados(38).csv -> 06-2013.csv\n",
      "Arquivo renomeado e movido: dados(39).csv -> 03-2013.csv\n",
      "Arquivo renomeado e movido: dados(40).csv -> 12-2012.csv\n",
      "Arquivo renomeado e movido: dados(41).csv -> 09-2012.csv\n",
      "Arquivo renomeado e movido: dados(42).csv -> 06-2012.csv\n",
      "Arquivo renomeado e movido: dados(43).csv -> 03-2012.csv\n",
      "Arquivo renomeado e movido: dados(44).csv -> 12-2011.csv\n",
      "Arquivo renomeado e movido: dados(45).csv -> 09-2011.csv\n",
      "Arquivo renomeado e movido: dados(46).csv -> 06-2011.csv\n",
      "Arquivo renomeado e movido: dados(47).csv -> 03-2011.csv\n",
      "Arquivo renomeado e movido: dados(48).csv -> 12-2010.csv\n",
      "Arquivo renomeado e movido: dados(49).csv -> 09-2010.csv\n",
      "Arquivo renomeado e movido: dados(50).csv -> 06-2010.csv\n",
      "Arquivo renomeado e movido: dados(51).csv -> 03-2010.csv\n",
      "Arquivo renomeado e movido: dados(52).csv -> 12-2009.csv\n",
      "Arquivo renomeado e movido: dados(53).csv -> 09-2009.csv\n",
      "Arquivo renomeado e movido: dados(54).csv -> 06-2009.csv\n",
      "Arquivo renomeado e movido: dados(55).csv -> 03-2009.csv\n",
      "Arquivo renomeado e movido: dados(56).csv -> 12-2008.csv\n",
      "Arquivo renomeado e movido: dados(57).csv -> 09-2008.csv\n",
      "Arquivo renomeado e movido: dados(58).csv -> 06-2008.csv\n",
      "Arquivo renomeado e movido: dados(59).csv -> 03-2008.csv\n",
      "Arquivo renomeado e movido: dados(60).csv -> 12-2007.csv\n",
      "Arquivo renomeado e movido: dados(61).csv -> 09-2007.csv\n",
      "Arquivo renomeado e movido: dados(62).csv -> 06-2007.csv\n",
      "Arquivo renomeado e movido: dados(63).csv -> 03-2007.csv\n",
      "Arquivo renomeado e movido: dados(64).csv -> 12-2006.csv\n",
      "Arquivo renomeado e movido: dados(65).csv -> 09-2006.csv\n",
      "Arquivo renomeado e movido: dados(66).csv -> 06-2006.csv\n",
      "Arquivo renomeado e movido: dados(67).csv -> 03-2006.csv\n",
      "Arquivo renomeado e movido: dados(68).csv -> 12-2005.csv\n",
      "Arquivo renomeado e movido: dados(69).csv -> 09-2005.csv\n",
      "Arquivo renomeado e movido: dados(70).csv -> 06-2005.csv\n",
      "Arquivo renomeado e movido: dados(71).csv -> 03-2005.csv\n",
      "Processo concluído.\n"
     ]
    }
   ],
   "source": [
    "import os\n",
    "import shutil\n",
    "\n",
    "# Lista de nomes de arquivos gerados\n",
    "nomes_gerados = []\n",
    "for number in range(72):\n",
    "    if number == 0:\n",
    "        nomes_gerados.append(\"dados\")\n",
    "    else:\n",
    "        nomes_gerados.append(f\"dados({number})\")\n",
    "\n",
    "# Lista de datas trimestrais no formato \"mm-yyyy\"\n",
    "datas_trimestrais = [\"12-2022\", \"09-2022\", \"06-2022\", \"03-2022\", \"12-2021\", \"09-2021\", \"06-2021\", \"03-2021\", \"12-2020\", \"09-2020\", \"06-2020\", \"03-2020\", \"12-2019\", \"09-2019\", \"06-2019\", \"03-2019\", \"12-2018\", \"09-2018\", \"06-2018\", \"03-2018\", \"12-2017\", \"09-2017\", \"06-2017\", \"03-2017\", \"12-2016\", \"09-2016\", \"06-2016\", \"03-2016\", \"12-2015\", \"09-2015\", \"06-2015\", \"03-2015\", \"12-2014\", \"09-2014\", \"06-2014\", \"03-2014\", \"12-2013\", \"09-2013\", \"06-2013\", \"03-2013\", \"12-2012\", \"09-2012\", \"06-2012\", \"03-2012\", \"12-2011\", \"09-2011\", \"06-2011\", \"03-2011\", \"12-2010\", \"09-2010\", \"06-2010\", \"03-2010\", \"12-2009\", \"09-2009\", \"06-2009\", \"03-2009\", \"12-2008\", \"09-2008\", \"06-2008\", \"03-2008\", \"12-2007\", \"09-2007\", \"06-2007\", \"03-2007\", \"12-2006\", \"09-2006\", \"06-2006\", \"03-2006\", \"12-2005\", \"09-2005\", \"06-2005\", \"03-2005\"]\n",
    "\n",
    "# Pasta de origem dos arquivos CSV\n",
    "pasta_origem = \"C:\\\\Users\\\\Arthur\\\\Downloads\"\n",
    "\n",
    "# Pasta de destino para os arquivos renomeados\n",
    "pasta_destino = \"F:\\\\BACKUP GERAL 01.06.2020\\\\UFSC\\\\2023\\\\Artigo Earnings Persistence\\\\Dados if.data - dez-2022 - mar-2005 (resumo)\"\n",
    "\n",
    "# Loop para renomear e mover os arquivos\n",
    "for i in range(len(nomes_gerados)):\n",
    "    nome_original = f\"{nomes_gerados[i]}.csv\"\n",
    "    nome_novo = f\"{datas_trimestrais[i]}.csv\"\n",
    "\n",
    "    caminho_original = os.path.join(pasta_origem, nome_original)\n",
    "    caminho_destino = os.path.join(pasta_destino, nome_novo)\n",
    "\n",
    "    # Verifique se o arquivo original existe\n",
    "    if os.path.exists(caminho_original):\n",
    "        # Renomeie e mova o arquivo para a pasta de destino\n",
    "        shutil.move(caminho_original, caminho_destino)\n",
    "        print(f\"Arquivo renomeado e movido: {nome_original} -> {nome_novo}\")\n",
    "    else:\n",
    "        print(f\"Arquivo original não encontrado: {nome_original}\")\n",
    "\n",
    "print(\"Processo concluído.\")\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
